package ${package}.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package}.pojo.bean.${className};
import ${package}.pojo.vo.${className}Vo;
import ${package}.pojo.query.${className}Query;
import ${package}.service.${className}Service;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.apps.security.annotation.AnonymousAccess;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* @Author ${author}
* @Date ${date}
*/
@RestController
@Api(tags = "${apiAlias}管理")
@RequestMapping("${changeClassName}")
@RequiredArgsConstructor
public class ${className}Controller {
    private final ${className}Service ${changeClassName}Service;

    @Log("添加${apiAlias}")
    @ApiOperation("添加${apiAlias}")
    @PostMapping("add${className}")
    @PreAuthorize("@el.check('add${className}')")
    public ResultMessage add${className}(@Validated ${className}Vo ${changeClassName}Vo){
        ${className} ${changeClassName} = BeanUtil.from(${changeClassName}Vo, ${className}.class);
        return ${changeClassName}Service.add${className}(${changeClassName});
    }

    @Log("删除${apiAlias}")
    @ApiOperation("删除${apiAlias}")
    @DeleteMapping("del${className}")
    @PreAuthorize("@el.check('del${className}')")
    public ResultMessage del${className}(@RequestParam List<Long> ids){
        return ${changeClassName}Service.del${className}(ids);
    }

    @Log("更改${apiAlias}")
    @ApiOperation("更改${apiAlias}")
    @PutMapping("edit${className}")
    @PreAuthorize("@el.check('edit${className}')")
    public ResultMessage edit${className}(@Validated ${className}Vo ${changeClassName}Vo){
        ${className} ${changeClassName} = BeanUtil.from(${changeClassName}Vo, ${className}.class);
        return ${changeClassName}Service.edit${className}(${changeClassName});
    }

    @Log("分页获得${apiAlias}列表")
    @ApiOperation("获得${apiAlias}列表")
    @GetMapping("page${className}")
    @PreAuthorize("@el.check('page${className}')")
    public ResultMessage page${className}(PageVo<${className}> pageVo, ${className}Query ${changeClassName}Query){
        Page<${className}> page = BeanUtil.fromPage(pageVo);
        return ${changeClassName}Service.page${className}(page, ${changeClassName}Query);
    }

    @Log("获得${apiAlias}详情")
    @ApiOperation("获得${apiAlias}详情")
    @GetMapping("get${className}")
    @PreAuthorize("@el.check('get${className}')")
    public ResultMessage get${className}(Long id){
        return ${changeClassName}Service.get${className}(id);
    }

    @Log("导出${apiAlias}列表")
    @ApiOperation("导出${apiAlias}列表")
    @GetMapping("export${className}")
    @PreAuthorize("@el.check('export${className}')")
        public void export${className}(HttpServletResponse response, ${className}Query ${changeClassName}Query){
        ${changeClassName}Service.export${className}(response, ${changeClassName}Query);
    }
}